<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加界面</title>
    <link href="http://localhost:8080/static/layui/css/layui.css" rel="stylesheet">
</head>
<body>

<form class="layui-form" action="javascript:void(0);">
    <div class="layui-form-item">
        <label class="layui-form-label">公告标题</label>
        <div class="layui-input-block">
            <input type="text" name="noticeTitle" required  lay-verify="required" placeholder="请输入公告标题" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">公告类型</label>
        <div class="layui-input-block">
            <select name="noticeType" lay-verify="required">
                <option value="">请选择公告类型</option>
                <option value="1">通知</option>
                <option value="2">公告</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="0" title="正常" checked>
            <input type="radio" name="status" value="1" title="停用">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block">
            <input type="text" name="noticeContent" required  lay-verify="required" placeholder="请输入内容" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <input type="text" name="remark" required  lay-verify="required" placeholder="请输入备注" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script src="http://localhost:8080/static/layui/layui.js"></script>
<script src="http://localhost:8080/static/layui/js/jquery-3.6.3.js"></script>
<script>
    //Demo
    layui.use('form', function () {
        let form = layui.form;

        //提交,form表单监听事件
        form.on('submit(formDemo)', function (data) {
            layer.msg(JSON.stringify(data.field));
            $.ajax({
                url: "http://localhost:8080/sysNotice/addNotice.do",
                data: data.field,
                type: "post",
                dataType: "json",
                success: function (res) {
                    //console.log(res);
                    if (res == 1) {
                        //添加成功，关闭当前弹窗层
                        layer.msg("添加成功");
                        let index = parent.layer.getFrameIndex(window.name);
                        //关闭当前窗口
                        parent.layer.close(index);
                        //刷新当前页面
                        parent.location.reload();
                    }
                },
                error: function () {
                    console.log(" err....");
                }
            });
        });
    });
</script>
</body>
</html>
